﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace DataModel
{
    public abstract class BaseAccess
    {
        public DataSet GetEntitis()
        {
            MySqlDataAdapter daCountry;
            DataSet dsCountry;

            string connStr = "server=localhost;user=root;database=world;port=3306;password=root;";
            MySqlConnection conn = new MySqlConnection(connStr);
            try
            {
                //label2.Text = "Connecting to MySQL...";

                string sql = "SELECT Code, Name, HeadOfState FROM Country WHERE Continent='North America'";
                daCountry = new MySqlDataAdapter(sql, conn);
                MySqlCommandBuilder cb = new MySqlCommandBuilder(daCountry);

                dsCountry = new DataSet();
                daCountry.Fill(dsCountry, "Country");
                return dsCountry;
            }
            catch (Exception ex)
            {
                //label2.Text = ex.ToString();
                return null;
            }

        }

        public int updateEntities(MySqlDataAdapter daCountry, DataSet dsCountry)
        {
            return daCountry.Update(dsCountry, "Country");//更新影响的行数
        }
    }
}
